<template>
  <div class="app-container formList">
    <el-form ref="detailForm">
      <div>
        <!-- <i class="MmsUiBlockTitle___line___27lhp1-44-1"></i> -->
        <div class="big_title_style" style="font-size: 18px">
          <span>基础信息</span>
        </div>
      </div>
      <el-divider></el-divider>
      <div style="margin-left: 50px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="结算单号">
              <span>{{ showData.settlementNo }}</span>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单数量">
              <span>{{ showData.orderNumber }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商品数量">
              <span>{{ showData.productNumber }}</span>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="售后金额">
              <span>{{ showData.serviceAmountTotal }} 元</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结算金额">
              <span>{{ showData.settlementMoney }} 元</span>
            </el-form-item>
          </el-col>
        </el-row>
      </div>

      <div>
        <!-- <i class="MmsUiBlockTitle___line___27lhp1-44-1"></i> -->
        <div class="big_title_style" style="font-size: 18px">
          <span>订单信息</span>
        </div>
      </div>
      <el-divider></el-divider>
      <div style="margin-left: 50px">
        <template>
          <el-table
            :data="tableData"
            height="400"
            :summary-method="getSummaries"
            show-summary
            style="width: 100%; margin-top: 20px">
            <el-table-column
              prop="orderNo"
              label="订单编号"
              width="150">
            </el-table-column>
            <el-table-column
              prop="proName"
              label="商品名称"
              width="150">
            </el-table-column>
            <el-table-column
              prop="skuDesc"
              label="商品描述"
              width="140">
            </el-table-column>
            <el-table-column
              prop="costPrice"
              label="供应价格（元）"
              width="120">
            </el-table-column>
            <el-table-column
              prop="itemNumber"
              label="销售数量"
              width="100">
            </el-table-column>
            <el-table-column
              prop="serviceNumber"
              label="售后数量"
              width="100">
            </el-table-column>
            <el-table-column
              prop="serviceAmount"
              label="售后金额（元）"
              width="120">
            </el-table-column>
            <el-table-column
              prop="settlementAmount"
              label="结算金额（元）"
              width="120">
            </el-table-column>
            <el-table-column
              prop="payTime"
              label="下单时间"
              width="170">
            </el-table-column>
          </el-table>
        </template>
      </div>

    </el-form>
  </div>
</template>

<script>
  import {
    getSettlementDetailById
  } from '@/api/supplier/settlement'

  export default {
    name: 'Settlement',
    components: {},
    data() {
      return {
        // 订单结算表格数据
        settlementList: [],
        // 弹出层标题
        title: '',
        //查看详细标题
        viewTitle: '订单详细',

        //查看详细数据
        showData: [],
        tableData: [],
        pickerOptions: {},
        // 表单参数
        form: {},
      }
    },
    props: {
      //是否显示
      viewOpen: {
        type: Boolean,
        default: false,
      },
      //是否显示
      settlementIdStr: {
        type: Number,
        default: null,
      },
    },
    created() {
      this.getOrderDetailById(this.settlementIdStr)
    },
    methods: {

      getSummaries(param) {
        const {columns, data} = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总价';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index];
          } else {
            sums[index] = 'N/A';
          }
        });

        return sums;
      },
      //查询订单详细
      getOrderDetailById(row) {
        getSettlementDetailById(row).then(response => {
          this.tableData = response.orderSettlementVos;
          this.showData = response;
        })
      },


    },
    //声明周期 - 创建完成（可以访问当前this实例）
    created() {
      if (this.settlementIdStr) {
        this.getOrderDetailById(this.settlementIdStr)
      }
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {
    },
  }
</script>

<style scoped>
  .MmsUiBlockTitle___line___27lhp1-44-1 {
    display: inline-block;
    background: #407cff;
    width: 2px;
    height: 16px;
    margin-right: 8px;
  }

  .MmsUiBlockTitle___title___2C-H-1-44-1 {
    display: inline-block;
    font-size: 20px;
    color: #333;
    position: relative;
  }

  .el-table {
    overflow: visible !important;
  }


</style>
